<template>
  <div>

    <el-container>
      <el-header  style="margin: 0 auto">
        <!--            <h1>物资操作流水记录</h1>-->
        <label style="color: darkturquoise;font-weight: bolder;font-size: larger;text-align: center">用户留言</label>
      </el-header>
    </el-container>

    <el-card class="big-box">
      <div style="padding-top: 30px">
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
          <div style="width: 400px">
            <el-form-item label="留言标题" prop="title">
              <el-input v-model="ruleForm.title"></el-input>
            </el-form-item>
          </div>

          <el-form-item label="留言内容" prop="content">
            <el-input type="textarea" v-model="ruleForm.content"></el-input>
          </el-form-item>
          <el-form-item>
            <!--              <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>-->
            <el-button @click="resetForm('ruleForm')">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-card>
    <div class="submit-btn" @click="submitForm('ruleForm')">提交留言</div>
  </div>
</template>
<script>
export default {
  name: 'userMsg',

  data() {
    return {
      ruleForm: {
        title: '',
        content: ''
      },
      rules: {
        title: [
          { required: true, message: '请输入标题', trigger: 'blur' },
          { min: 2, max: 15, message: '长度在 3 到 15 个字符', trigger: 'blur' }
        ],
        content: [
          { required: true, message: '请填写留言内容', trigger: 'blur' }
        ]
      }
    };
  },

  mounted() {

  },

  methods: {
    submitForm(formName) {
      const user = JSON.parse(window.sessionStorage.getItem("user"))
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // alert('submit!');
          // console.log(this.ruleForm)
          this.$http.post("/user/message/"+user.id,this.ruleForm).then(res=>{
            if (res.data.status) {
              this.$message.success(res.data.data);
              this.resetForm(formName)
            } else {
              this.$message.error(res.msg);
            }
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  },
};
</script>

<style lang="less" scoped>
.big-box{
  width: 800px;
  height: 300px;
  //background-color: aquamarine;
  margin: 50px auto;
}
.submit-btn{
  margin: 50px auto;
  width: 150px;
  height: 40px;
  background-color: #f59937;
  border-radius: 5px;
  text-align: center;
  line-height: 40px;
  color: white;
}
.feedback-head{
  margin: 20px auto;
}
</style>
